package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.mapper.BaseAttrValueMapper;
import com.atguigu.gmall.product.service.ManagerService;
import com.baomidou.mybatisplus.extension.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: BaseManagerController
 * Package: com.atguigu.gmall.product.controller
 * Description:
 *
 * @Author: cqk
 * @Create: 2023/10/16 - 10:02
 * @Version: v1.0
 */
@RestController
@RequestMapping("/admin/product")
//@CrossOrigin
public class BaseManagerController {
    @Autowired
    private ManagerService managerService;


    /**
     * getAttrValueList/{attrId}
     * 根据attrId获取属性值
     */
    @GetMapping("getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable Long attrId){
        BaseAttrInfo baseAttrInfo = managerService.getAttrInfo(attrId);
        List<BaseAttrValue> attrValueList = baseAttrInfo.getAttrValueList();

        return Result.ok(attrValueList);

    }


    /**
     * 新增或者修改属性
     */
    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){

        managerService.saveAttrInfo(baseAttrInfo);

        return Result.ok();
    }


    /**
     * 根据分类id查询
     *///    attrInfoList/{category1Id}/{category2Id}/{category3Id}

    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result  attrInfoList(@PathVariable Long category1Id,
                                @PathVariable Long category2Id,
                                @PathVariable Long category3Id){
        List<BaseAttrInfo> list = managerService.attrInfoList(category1Id,category2Id,category3Id);

        return Result.ok(list);
    }


    /**
     * 查询一级分类
     */
    @GetMapping("/getCategory1")
    public Result getCategory1(){

        List<BaseCategory1> baseCategory1List =  managerService.getCategory1();
        return Result.ok(baseCategory1List);
    }

    /**
     * 根据一级分类id查询二级分类
     */
    @GetMapping("/getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable Long category1Id){

        List<BaseCategory2> baseCategory2List =  managerService.getCategory2(category1Id);
        return Result.ok(baseCategory2List);
    }

    /**
     * 根据一级分类id查询二级分类
     */
    @GetMapping("/getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable Long category2Id){

        List<BaseCategory3> baseCategory3List =  managerService.getCategory3(category2Id);
        return Result.ok(baseCategory3List);
    }

}
